<?php
require '../config.php';
$resultset = mysql_query($_REQUEST['query'],$conexion);

if(!$resultset)
{
    mysql_close();
    echo json_encode('error en el query: ' . mysql_error());
}
elseif(!mysql_num_rows($resultset))
{
    mysql_close();
    echo json_encode('Sin resultados');
}
else
{
	?>
			
			<button type="button" class="btn btn-default" onclick="reportarpdf2();" >Imprimir <span class= 'glyphicon glyphicon-print'></span>  </button>
					<?php
			echo   "<table class='table table-bordered'>";
			
			echo   "<tr>";
			echo   "<th>Id llamada</th><th>Id Cliente</th><th>C&eacute;dula</th><th>Cliente</th><th>Fecha</th><th>Id Usuario</th><th>Usuario</th><th>Efectividad</th><th>Observaci&oacute;n</th><th>Motivo</th>";
			echo   "</tr>";
			echo   "<tbody>";
			$aux=0;
			while($row = mysql_fetch_assoc($resultset))
			{
				if($aux==0){
					$color="#FFFFFF";
					$aux=1;
				}else{
					$color="#F9F9F9";
					$aux=0;
				}
				echo ("<tr bgcolor='".$color."'>");
				echo   "<td>".$row['idregllamadas']."</td>";
				echo   "<td>".$row['idcliente']."</td>";
				echo   "<td>".$row['cedula']."</td>";
				echo   "<td>".$row['nombres']." ".$row['apellidos']."</td>";
				echo   "<td>".date("d M Y h:m:s",strtotime($row['fecha']))."</td>";
				echo   "<td>".$row['idusuario']."</td>";
				echo   "<td>".$row['nombre']." ".$row['apellido']."</td>";
				echo   "<td>".retornaEfectividad($row['efectividad'])."</td>";
				echo   "<td>"._convert($row['nota'])."</td>";
				echo   "<td>"._convert($row['motivo'])."</td>";
				echo   "</tr>";
			}
			echo   "</tbody>";
			echo   "</table>";
			mysql_close();
		
}

function retornaEfectividad($valor)
{
	if($valor==1) return '<span class= "glyphicon glyphicon-ok"></span>';
	else 
		return '<span class= "glyphicon glyphicon-minus"></span>';
}
function _convert($content) {
	if(!mb_check_encoding($content, 'UTF-8')
	OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {

		$content = mb_convert_encoding($content, 'UTF-8');

		if (mb_check_encoding($content, 'UTF-8')) {
			// log('Converted to UTF-8');
		} else {
			// log('Could not converted to UTF-8');
		}
	}
	return $content;
}
?>